// 构建SingleDeptTree   
    SingleDeptTreeUI = function(){   
        return { 
            // --------------- tree选中节点------------------- 
            deptNode:'undefined',
            companyId:'undefined',
            companyName:'undefined',
            // --------------- 内部函数 将tree选取的值保存在全局变量deptNode中-------------------
	        departSave : function(node){
	            this.deptNode = node.id;
	        },
            // --------------- Action 保存选择的节点 -------------------
            selectF : function() {
                this.select = new Ext.Action({
                    scope: this,
			        text: '选择',
			        iconCls: 'btn_select',
			        handler: function(){
			            if(this.departMentTree.curNode == 'undefinded'){
			               Ext.Msg.alert('提示', '请选择节点！');    
			               return;     
			            }
			            if(this.departMentTree.curNode.id == this.departMentTree.specialNode.id) {                       
		                   Ext.Msg.alert('提示', '不能选择自己作为上级用户组！');     
		                   return false;
		                }
			            this.departSave(this.departMentTree.curNode);
			            this.window.hide();
			        }
			    });
            },
            // --------------- Action 隐藏此页面 -------------------
            channelF : function() {
                this.channel = new Ext.Action({
                    scope: this,
			        text: '取消',
			        iconCls: 'btn_cancel',
			        handler: function(){
			           this.window.hide();
			        }
			    });
            },
            // --------------- Action 初始化部门树 -------------------
            departMentTreeF: function(){
                this.departMentTree = new Ext.tree.TreePanel({                                          
	               id:'ds-tree',                        
	               loader: new Ext.tree.TreeLoader(),
	               rootVisible:false,
	               lines:false,
	               autoScroll:true,
	               autoHeight:false, 
	               specialNode: 'undefineded',                  
	               curNode: 'undefinded',                     
	               root:new Ext.tree.AsyncTreeNode({
	                   id : this.companyId,
	                   text: this.companyName
	               }),
	               loader:new Ext.tree.TreeLoader({                            
	                   url : Ext.SERVER+'org/expendDepartMentTree.do'
	               }),
	               listeners: {
	                   click: function(n) {
	                       this.curNode = n;
	                       //Ext.Msg.alert('Navigation Tree Click', 'You clicked: "' + n.attributes.text + '"');
	                   },
                       beforeload: function(node){
                            // 用户组树需要应用程序ID作为参数
                            if(SingleDeptTreeUI.departMentTree.companyId == 'undefineded'||SingleDeptTreeUI.departMentTree.companyId == ''){                            
                                return false;
                            }
                            if(node.id == SingleDeptTreeUI.departMentTree.specialNode.id) {
                                 Ext.Msg.alert('提示', '不能选择当前用户组的下级或者本级用户组作为上级用户组！');     
                                 return false;
                            }// 此节点不能被展开                        
                       }
	               }                                   
			   });
            },
            // --------------- window 初始化部门单选窗口 -------------------
            windowF: function(){
                this.window = new Ext.Window({
                    width:300, height: 300,
                    closeAction: 'hide',
                    layout: 'fit', // explicitly set layout manager: override the default (layout:'auto')
                    tbar:[this.select, this.channel],
                    items: [this.departMentTree]
                });
            },
            // --------------- Action 初始化本页面 -------------------
            init: function(companyId, companyName){
                this.companyId = companyId;
                this.companyName = companyName;
                this.selectF();
                this.channelF();
                this.departMentTreeF();
                this.windowF();
            }
        }
    }();